What is logkitty?
Logkitty is a tool for reading Android logcat logs. It provides a simple and efficient way to filter and display log messages from Android devices, making it easier to debug and monitor applications.
What are logkitty's main functionalities?
Basic Logcat Reading
This feature allows you to start reading logcat logs from an Android device. The code sets up a logkitty reader and starts it, printing each log entry to the console.
const { logkitty, android } = require('logkitty');
const reader = logkitty();
reader.on('entry', entry => console.log(entry));
reader.start();
Filtering Logs
This feature allows you to filter logcat logs by specific tags. The code sets up a logkitty reader with a filter to only show logs tagged with 'MyApp'.
const { logkitty, android } = require('logkitty');
const reader = logkitty({ filter: [android.filters.byTag('MyApp')] });
reader.on('entry', entry => console.log(entry));
reader.start();
Custom Log Entry Formatting
This feature allows you to customize the format of log entries. The code sets up a logkitty reader and formats each log entry to display the tag and message.
const { logkitty, android } = require('logkitty');
const reader = logkitty();
reader.on('entry', entry => console.log(`${entry.tag}: ${entry.message}`));
reader.start();
Other packages similar to logkitty
adbkit-logcat
adbkit-logcat is a Node.js library for reading Android logcat logs. It provides similar functionality to logkitty, allowing you to read and filter logcat logs. However, adbkit-logcat is part of the larger adbkit suite, which includes additional tools for interacting with Android devices.
logkitty
Display pretty Logcat logs without Android Studio with intuitive Command Line Interface.
Installation
yarn global add logkitty
Or if you prefer having it locally:
yarn add -D logkitty
yarn logkitty --help
Usage
logkitty <command> [options]
Commands
tag <tags...>
- Show logs with matching tags.app <appId>
- Show logs from application with given identifier.match <regexes...>
- Show logs matching given patterns (all regexes have flags g
and m
).custom <patterns...>
- Use custom patters supported by Logcat.all
- Show all logs.
Options
Common
All command accept the following options:
--adb-path <path>
- Custom path to ADB executable/binary.-h, --help
- Display help-v, --version
- Display version
Specific
tag
, app
, match
and all
commands support additional filtering options (sorted by priority):
-U, -u
- Unknown priority (lowest)-v, -v
- Verbose priority-D, -d
- Debug priority (default)-I, -i
- Info priority-W, -w
- Warn priority-E, -e
- Error priority-F, -f
- Fatal priority-S, -s
- Silent priority (highest)
For example logkitty all -W
will display all logs with priority warn, error and fatal.
Examples
Show all logs with tag ReactNativeJS
(and default priority - debug and above):
logkitty tag ReactNativeJS
Show all logs with priority info and above from application with identifier com.example.myApplication
:
logkitty app com.example.myApplication -i
Show all logs matching /CodePush/gm
regex:
logkitty match CodePush
Show all logs with priority error or fatal:
logkitty all -e
Show logs using custom patterns - silence all logs and display only the onces with tag my-tag
and priority debug and above:
logkitty custom *:S my-tag:D
Node API
Example:
import {
logkitty,
makeTagsFilter,
formatEntry,
formatError,
Priority,
Entry,
} from 'logkitty';
const emitter = logkitty({
platform: 'android',
minPriority: Priority.VERBOSE,
filter: makeTagsFilter('ReactNative', 'ReactNativeJS'),
});
emitter.on('entry', (entry: Entry) => {
console.log(formatEntry(entry));
});
emitter.on('error', (error: Error) => {
console.log(formatError(error));
});
logkitty(options: LogkittyOptions): EventEmitter
Spawns logkitty with given options:
platform: 'android'
- Platform, currently the only supported one is android
.adbPath?: string
- Custom path to ADB tool or undefined
.priority?: number
- Minimum priority of entries to show of undefined
, which will include all entries with priority DEBUG or above.filter?: FilterCreator
- The returned value from makeTagsFilter
/makeAppFilter
/makeMatchFilter
/makeCustomFilter
or undefined
, which will include all entries (similar to all
command in the CLI).
When spawning logkitty you will get a instance of EventEmitter
which emitts the following events:
entry
(arguments: entry: Entry
) - Emitted when new log comes in, that matches the filter
and priority
options. It is your responsibility to print or use that entry, for example you can use formatEntry
to print it with the same styling as in the CLI.error
(arguments: error: Error
) - Emitted when the log can't be parsed into a entry or when the Logcat process emits an error. You can use formatError
to print it with the same styling as in the CLI.
makeTagsFilter(...tags: string[]): FilterCreator
Creates a filter from given tags (for example ReactNative
, ReactNativeJS
), so only entries matching any of the given tags will be emitted in entry
event. Pass the returned value to filter
property when running logkitty
.
makeAppFilter(appIdentifier: string): FilterCreator
Creates a filter for given application identifier (for example com.example.app
), so only entries from given app will be emitted in entry
event. Pass the returned value to filter
property when running logkitty
.
makeMatchFilter(...regexes: RegExp[]): FilterCreator
Creates a filter from given regexes (for example /ReactNative/gm
, /ReactNativeJS/gm
), so only entries matching any of the given regexes will be emitted in entry
event. Pass the returned value to filter
property when running logkitty
.
makeCustomFilter(...patterns: string[]): FilterCreator
Creates a custom filter (for example *:S
, ReactNative:D
, Hello:E
), so only entries matching given patterns will be emitted in entry
event. Pass the returned value to filter
property when running logkitty
.
formatEntry(entry: Entry): string
Takes an entry as formats it to a string with ANSI escape codes for coloring.
formatError(error: Error): string
Takes an error and formats it to a string with ANSI escape codes for coloring.